k8s Q&A [updating...]
1. how to stop pod that still terminating #
Sometimes there was a pod keep in terminating status. For example, the terminationGracePeriodSeconds being set to a very large value.
Do not force delete pod through kubectl delete pod -f option, this will cause container process residual on node unless you make sure the container on node already terminated.
You can stopping by following ways.
- attact to pod container, find which PID that block container exit, then kill it;
- if the block process is init process(PID is 1), then do the following steps.
if k8s using containerd as runtime, try using ctr command.
ctr -n k8s.io container ls | grep $imageName
#find taskID
ctr -n k8s.io task kill taskID
Or using crictl
crictl ps -a | grep $podName
crictl stop $containerID
- Why
ctr c lsshows nothing? All k8s pod containerd run ink8s.ionamespace,containerd namespaceis notPOD namespacein k8s, containerd usedefaultas default namespace containerd's containeris different fromdocker container. when contaienrd create container, the container just be created but not started. ctr start will launch container process, this calls task.